project(VruiOpenGL)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

 
IF(CMAKE_CONFIGURATION_TYPES)
   SET(CMAKE_CONFIGURATION_TYPES Debug Release)
   set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
     "Reset the configurations to what we need"
     FORCE)
ENDIF()

# Generate folder name for install
IF(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
	SET(BITS "x64")
ELSEIF (${CMAKE_SIZEOF_VOID_P} EQUAL 4)
	SET(BITS "x86")
ENDIF()

IF (MSVC)
	IF (${MSVC_VERSION} EQUAL 1600)
		SET(COMPILER "v100") # Visual Studio 2010
	ELSEIF (${MSVC_VERSION} EQUAL 1700)
		SET(COMPILER "v110") # Visual Studio 2012
	ELSEIF (${MSVC_VERSION} EQUAL 1800)
		SET(COMPILER "v120") # Visual Studio 2013
	ELSEIF (${MSVC_VERSION} EQUAL 1900)
		SET(COMPILER "v140") # Visual Studio 2015
	ENDIF()
ENDIF()

IF(MINGW)
	SET(COMPILER "mingw")
ENDIF()

SET(dirname "${COMPILER}-${BITS}")

#Set directories
SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/3rdParty/${dirname}/bin")
SET(ARCHIVE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/3rdParty/${dirname}/lib")
SET(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")
SET(INCLUDE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/3rdParty/${dirname}/include")


SET(ZLIB_SOURCE_DIR CACHE PATH "Path where to find ZLIB source")
SET(LIBPNG_SOURCE_DIR CACHE PATH "Path where to find LIBPNG source")
SET(LIBJPEG_SOURCE_DIR CACHE PATH "Path where to find LIBJPEG source")
SET(LIBTIFF_SOURCE_DIR CACHE PATH "Path where to find LIBTIFF source")
SET(FREETYPE_SOURCE_DIR CACHE PATH "Path where to find FREETYPE source")
SET(GLUT_SOURCE_DIR CACHE PATH "Path where to find GLUT source")
SET(GIFLIB_SOURCE_DIR CACHE PATH "Path where to find GIFLIB source")
SET(MINIZIP_SOURCE_DIR CACHE PATH "Path where to find MINIZIP source")
SET(CURL_SOURCE_DIR CACHE PATH "Path where to find cURL source")
SET(GLEW_SOURCE_DIR CACHE PATH "Path where to find GLEW source")

# Check dependencies for LIBPNG
IF (LIBPNG_SOURCE_DIR)
	IF(NOT ZLIB_SOURCE_DIR)
		MESSAGE(FATAL_ERROR "Error: LIBPNG depends on ZLIB and no ZLIB path has been set")
	ENDIF()
ENDIF ()

# Check dependencies for LIBTIFF
IF(LIBTIFF_SOURCE_DIR)
	IF(NOT ZLIB_SOURCE_DIR)
		MESSAGE(FATAL_ERROR "Error: LIBTIFF depends on ZLIB and no ZLIB path has been set")
	ENDIF()

	IF(NOT LIBJPEG_SOURCE_DIR)
		MESSAGE(FATAL_ERROR "Error: LIBTIFF depends on LIBJPEG and no LIBJPEG path has been set")
	ENDIF()
ENDIF()

# Check dependencies for MINIZIP
IF (MINIZIP_SOURCE_DIR)
	IF(NOT ZLIB_SOURCE_DIR)
		MESSAGE(FATAL_ERROR "Error: MINIZIP depends on ZLIB and no ZLIB path has been set")
	ENDIF()
ENDIF ()

# Add libraries
IF (ZLIB_SOURCE_DIR)
	ADD_SUBDIRECTORY(zlib)
	if (WIN32)
		SET_PROPERTY(TARGET zlib PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (LIBPNG_SOURCE_DIR)
	ADD_SUBDIRECTORY(libpng)
	if (WIN32)
		SET_PROPERTY(TARGET png PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (LIBJPEG_SOURCE_DIR)
	ADD_SUBDIRECTORY(libjpeg)
	if (WIN32)
		SET_PROPERTY(TARGET jpeg PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (LIBTIFF_SOURCE_DIR)
	ADD_SUBDIRECTORY(libtiff)
	if (WIN32)
		SET_PROPERTY(TARGET libtiff PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (FREETYPE_SOURCE_DIR)
	ADD_SUBDIRECTORY(freetype)
    include_directories(${FREETYPE_SOURCE_DIR}/include)
    include_directories("${FREETYPE_SOURCE_DIR}/include/freetype")
    include_directories("${FREETYPE_SOURCE_DIR}/include/freetype/internal")
	if (WIN32)
		SET_PROPERTY(TARGET freetype PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (GLUT_SOURCE_DIR)
	ADD_SUBDIRECTORY(glut)
	if (WIN32)
		SET_PROPERTY(TARGET glut PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (GIFLIB_SOURCE_DIR)
	ADD_SUBDIRECTORY(giflib)
	if (WIN32)
		SET_PROPERTY(TARGET giflib PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (MINIZIP_SOURCE_DIR)
	ADD_SUBDIRECTORY(minizip)
	if (WIN32)
		SET_PROPERTY(TARGET minizip PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (CURL_SOURCE_DIR)
	ADD_SUBDIRECTORY(curl)
	if (WIN32)
		SET_PROPERTY(TARGET curl PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()

IF (GLEW_SOURCE_DIR)
	ADD_SUBDIRECTORY(glew)
	if (WIN32)
		SET_PROPERTY(TARGET glew PROPERTY FOLDER "3rdparty")
	endif()
ENDIF()



add_subdirectory(SDL2-2.0.4)

include_directories(${CMAKE_SOURCE_DIR}/SDL2-2.0.4/include)



add_subdirectory(SDL2ttf)
add_dependencies(SDL2ttf SDL2)

add_subdirectory(test)
add_dependencies(test SDL2 SDL2main)

if (WIN32)
	SET_PROPERTY(TARGET SDL2 PROPERTY FOLDER "SDL2")
	SET_PROPERTY(TARGET SDL2main PROPERTY FOLDER "SDL2")
	SET_PROPERTY(TARGET SDL2ttf PROPERTY FOLDER "SDL2")
	SET_PROPERTY(TARGET uninstall PROPERTY FOLDER "SDL2")
	SET_PROPERTY(TARGET test PROPERTY FOLDER "Tests")
endif()
